import $http from '@/api/request.js'
import store from '@/store/index.js'
import pop from '@/common/pop.js'

class MannerOrder {
	
	// 获取师傅订单数量
	async GetStaffListCount(){ 
		try{
			const response = await $http.get({
				url: '/orderRepairApi/getStaffListCount'
			})
			if(response.code != 200) return pop.Toast(response.msg);
			return response.data
		}catch{
			throw error
		}
	}
	
	// 获取订单列表
	async GetrepairOrderList(reuqestObj){  
	   try{
		   const response = await $http.get({
		   	url: '/orderRepairApi/repairOrderList',
		   	data: reuqestObj
		   })
		   if(response.code != 200) return pop.Toast(response.msg);
		    return response.data
	   }catch{
		   throw error
	   }
	}
	
	// 接单
	async Post_receive(repair_id){  
		try{
		   pop.showLoading('');
		   const response = await $http.post({
			url: '/orderRepairApi/receive',
			data: {
				repair_id
			}
		   })
		   if(response.code != 200) return pop.Toast(response.msg);
		    pop.hideLoading('');
			return response.data
		}catch{
			pop.hideLoading('');
			throw error
		}
	}
	
	// 拒绝订单(驳回)
	async Post_reject(repair_id,reason){  
		try{
		   pop.showLoading('');
		   const response = await $http.post({
			url: '/orderRepairApi/reject',
			data: {
				repair_id,
				reason
			}
		   })
		   if(response.code != 200) return pop.Toast(response.msg);
		    pop.hideLoading('');
			return response.data
		}catch{
			pop.hideLoading('');
			throw error
		}
	}
	
	
	// 派单
	async Post_accept(requestData){
		try{
		   pop.showLoading('');
		   const response = await $http.post({
				url: '/orderRepairApi/accept',
				data: requestData
		   })
		   if(response.code != 200) return pop.Toast(response.msg);
		    pop.hideLoading('');
			return response.data
		}catch{
			pop.hideLoading('');
			throw error
		}
	}
		
	// 核算价格
	async Post_changePayment(requestData){
		try{
		   pop.showLoading('');
		   const response = await $http.post({
				url: '/orderRepairApi/changePayment',
				data: requestData
		   })
		   if(response.code != 200) return pop.Toast(response.msg);
		    pop.hideLoading('');
			return response.data
		}catch{
			pop.hideLoading('');
			throw error
		}
	}
	
	// 获取师傅列表
	async Get_getMaster(cate_ids){
		try{
		   pop.showLoading('');
		   const response = await $http.get({
				url: '/orderRepairApi/getMaster',
				data: {
					cate_ids
				}
		   })
		   if(response.code != 200) return pop.Toast(response.msg);
		    pop.hideLoading('');
			return response.data
		}catch{
			pop.hideLoading('');
			throw error
		}
	}
	
	// 确定预约时间
	
	async Post_predictionOrder(repair_id,service_time,service_hour_time){
		try{
		   pop.showLoading('');
		   const response = await $http.post({
				url: '/orderRepairApi/predictionOrder',
				data: {
					repair_id,
					service_time,
					service_hour_time
				}
		   })
		   if(response.code != 200) return pop.Toast(response.msg);
		    pop.hideLoading('');
			return response.data
		}catch{
			pop.hideLoading('');
			throw error
		}
	}
	
}

export default new MannerOrder()
